package org.zerta.troops.server;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class ServerPanel extends JPanel implements ActionListener {

	static final long serialVersionUID = 1L;
	private TroopsServer troopsServer;
	JTextField mapFileField;
	JButton startServerButton;
	JButton startGameButton;
	ServerConsole console;

	public ServerPanel (TroopsServer troopsServer) {
		this.troopsServer = troopsServer;
		mapFileField = new JTextField("Colors");
		add(mapFileField);
		
		startServerButton = new JButton("Start Server");
		startServerButton.setActionCommand("START_SERVER");
		add(startServerButton);
		startServerButton.addActionListener(this);
		
		startGameButton = new JButton("Start Game");
		startGameButton.setActionCommand("START_GAME");
		// FIXME this button-shit does not work
		//startGameButton.setEnabled(false);
		add(startGameButton);
		startGameButton.addActionListener(this);
		
		console = new ServerConsole();
		add(console.getField());
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if ("START_SERVER".equals(e.getActionCommand())) {
			troopsServer.startServer(mapFileField.getText());
		} else if ("START_GAME".equals(e.getActionCommand())) {
			// FIXME this button-shit does not work
			// startServerButton.setEnabled(false);
			// startGameButton.setEnabled(true);
			troopsServer.startGame();
		}
	}
	
	public ServerConsole getConsole() {
		return console;
	}

}
